package com.baidu.controller;

import com.baidu.pojo.Issue;
import com.baidu.service.IssueService;
import com.baidu.utils.PageResult;
import com.baidu.utils.Result;
import com.baidu.utils.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author ZYH
 * @version 1.0
 * @description:TODO
 * @date 2022/1/7 14:56
 */
@RestController
@RequestMapping("issue")
public class IssueCotroller {
    @Autowired
    private IssueService issueService;

    @RequestMapping("list")
    public Result getList(){
        List<Issue> list = issueService.getList();
        return new Result(StatusCode.SUCCESS,true,"请求列表",list);
    }

    @RequestMapping("search/{pageNum}/{pageSize}")
    public Result searchList(@PathVariable Integer pageNum, @PathVariable Integer pageSize, @RequestBody Map search){
        PageResult search1 = issueService.search(pageNum, pageSize, search);
        return new Result(StatusCode.SUCCESS,true,"分页",search1);
    }

    @RequestMapping("add")
    public Result saveIssue(@RequestBody Issue issue){
        issueService.saveIssue(issue);
        return new Result(StatusCode.SUCCESS,true,"增加",null);
    }

    @RequestMapping("update")
    public Result updateIssue(@RequestBody Issue issue){
         issueService.updateIssue(issue);
        return new Result(StatusCode.SUCCESS,true,"修改",null);
    }
    @RequestMapping("delete/{issueid}")
    public Result delIssue(@PathVariable Integer issueid){
        issueService.deleteIssue(issueid);
        return new Result(StatusCode.SUCCESS,true,"删除",null);
    }
}
